<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Controller_Action_Secure
 * @copyright  Copyright (c) 2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: FileController.php 1006 2009-08-11 19:26:22Z Nathan Keyes $
 */
class Bushido_Controller_Action_File extends Bushido_Controller_Action
{

	public function viewAction()
	{
		$fileId = $this->_getParam('file_id');		
		$files = Bushido_Db_Table::getTable('Bushido_DbTable_File');		
		$file = $files->find($fileId)->current();
		if($file)
		{
			//Zend_Debug::dump($file->filename);
			$this->_helper->layout->disableLayout();
			$this->getResponse()->setHeader('Content-type', $file->mime_type)
			->setHeader('Content-length', $file->size)
			//->setHeader('Content-disposition', 'attachment;')
			//->setHeader('Content-disposition', 'attachment;filename="' . $file->filename . '"')
			->setBody($file->content);
			//Zend_Debug::dump($this->getResponse()->getHeaders());exit;
			$this->getResponse()->sendResponse();
		}
		else
		{
			throw new Bushido_Db_Table_Exception_RowNotFound();
		}
	}
}